package cn.always.xiajia.admin.sys.service.impl;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Service;

import cn.always.xiajia.admin.sys.entity.SysUserPost;
import cn.always.xiajia.admin.sys.mapper.SysUserPostMapper;
import cn.always.xiajia.admin.sys.service.SysUserPostService;
import cn.always.xiajia.framework.common.util.ExtCollUtil;
import cn.always.xiajia.framework.common.util.ExtCollectionUtils;
import cn.always.xiajia.framework.mybatis.core.service.impl.BaseServiceImplX;

/**
 * 
 * @author xgj
 *
 */
@Service("sysUserPostService")
public class SysUserPostServiceImpl extends BaseServiceImplX<SysUserPostMapper, SysUserPost> implements SysUserPostService {
	/**
	 * 根据用户获取对应岗位Id
	 * 
	 * @param userId
	 * @return
	 */
	@Override
	public Set<Long> getPostIdByUserId(Long userId) {
		if (userId == null) {
			return Collections.emptySet();
		}
		Map<String, Object> param = new HashMap<>();
		param.put("EQ_userId", userId);
		return ExtCollectionUtils.convertSet(xjList(param), SysUserPost::getPostId);
	}

	/**
	 * 获得拥有岗位的用户编号集合
	 *
	 * @param postId 岗位编号
	 * @return 用户编号集合
	 */
	@Override
	public Set<Long> getUserIdByPostId(Long postId) {
		return getUserIdByPostIds(Collections.singletonList(postId));
	}

	/**
	 * 获得拥有多个岗位的用户编号集合
	 *
	 * @param postIds 岗位编号集合
	 * @return 用户编号集合
	 */
	@Override
	public Set<Long> getUserIdByPostIds(Collection<Long> postIds) {
		if (ExtCollUtil.isEmpty(postIds)) {
			return Collections.emptySet();
		}
		Map<String, Object> param = new HashMap<>();
		param.put("IN_postId", postIds);
		return ExtCollectionUtils.convertSet(xjList(param), SysUserPost::getUserId);
	}
}
